#ifndef BINARYTREE_H
#define BINARYTREE_H

#include <stdlib.h>
/* typedef bool (*cmpFunc_t) () */
#define cmpFunc_def bool (*TCmpFunc) (const TKey &, const TKey &) 

/* Operator "<<" should be overloaded for TData data type */
/* If TCmpFunc is NULL operator 16603">" should be overloaded */
template < class TKey, class TData> class BTree

{
/*  Node part */
  public:
    /* constructors */
    BTree( ) 
    : mParent(NULL), mLeft(NULL), mRight(NULL)
    {};

    /* copy-constructor */
    BTree( const BTree  &node );

    /* destructor */
    ~BTree(); 

    /* functions: get */
    BTree * left() const { return mLeft; };
    BTree * right() const { return mRight; };
    BTree * parent() const { return mParent; };
    /*
    BTree * next() const; 
    BTree * prev() const;
    */

    /* functios: is */
    bool isLeft() const { return (mLeft == NULL) ? false : true; };
    bool isRight() const { return (mRight == NULL) ? false : true; };
    bool isParent() const { return (mParent == NULL) ? false : true; };

    TKey key() const { return mKey; } ;
    TData data() const { return mData; } ;
    TData *pData() const {  return &mData; };

    /* functions: set */
    void setData( const TData &aData ) { mData = aData; };
    void setKey( const TKey &aKey ) { mKey = aKey; };

    void setLeft( BTree *node ) { mLeft = node; };
    void setRight( BTree *node ) { mRight = node; };
    void setParent( BTree *node ) { mParent = node; };

    /* Tree */
    void print( ) const {};
    void printNode() const {};
    bool rm( TKey aKey );
    bool replace( TKey oldKey, TKey newKey );
    bool find( TKey aKey ) const;
    void add( TKey, TData );
    static void treatmentTree( BTree *,  void (*)( TData * ) );

    BTree & Min() const;
    BTree & Max() const;
  private:
    /* functions */
    BTree * search( const TKey ) const;
    BTree & insert( TKey, TData );

    /* data */
    TKey mKey;
    TData mData;

    BTree< TKey, TData > * mParent;
    BTree< TKey, TData > * mLeft;
    BTree< TKey, TData > * mRight;

};

#include "binarytree.cpp"

#endif

